// -*- coding: utf-8 -*- 
/**
 * Project: PICProcess
 *
 * @author: yanking
 * Create time: 2022-04-20 23:23
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package HistogramEqualization;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import java.io.File;
import java.io.IOException;

public class Chart {
    public void createBarChart(String filePath, double[] count, String rowKey) {
        filePath += "直方图.jpg";
        try {
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            for (int i = 0; i < count.length; i++) {
                Integer I = new Integer(i);
                dataset.addValue(count[i], rowKey, I.toString());
            }
            JFreeChart chart = ChartFactory.createBarChart3D("灰度直方图", "灰度值",
                    "数量", dataset, PlotOrientation.VERTICAL, true, true, false);

            ChartUtilities.saveChartAsJPEG(new File(filePath), chart, 400, 300);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void createLineChart(String filePath, double[] NSK) {
        filePath += "灰度变换曲线图.jpg";
        try {
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            for (int i = 0; i < NSK.length; i++) {
                Integer I = new Integer(i);
                dataset.addValue(NSK[i], "灰度变换", I.toString());
            }
            JFreeChart chart = ChartFactory.createLineChart("灰度变换曲线", "原灰度值",
                    "变换后灰度值", dataset, PlotOrientation.VERTICAL, true, false, false);

            ChartUtilities.saveChartAsJPEG(new File(filePath), chart, 500, 500);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
